1. Field of the Invention
The present invention relates to a data processing apparatus and method for controlling access to a shared resource in a data processing apparatus, and in particular controlling such access in a data processing apparatus having a plurality of processors operable to perform respective data processing operations requiring access to the shared resource.
2. Description of the Prior Art
It is known to provide multi-processing systems in which two or more processor cores share access to one or more shared resources, for example one or more data structures provided within a shared memory region. Such systems are typically used to gain higher performance by arranging the different processor cores to execute respective data processing operations in parallel. Known data processing systems which provide such multi-processing capabilities include IBM370 systems and SPARC multi-processing systems. These particular multi-processing systems are high performance systems where power efficiency and power consumption is of little concern and the main objective is maximum processing speed.
An important consideration in multi-processing systems where the multiple processors have access to a shared resource is the provision of a mechanism to control access to that shared resource to ensure that the data of that resource does not become inconsistent or corrupted due to multiple processors accessing the resource simultaneously. To deal with this issue, a typical multi-processor operating system may provide an access control mechanism such as a locking mechanism to protect the shared resource from being accessed by multiple processors simultaneously to prevent the data of the shared resource becoming inconsistent or corrupted if conflicting changes are made. If a lock is busy, i.e. has been set by one of the processors, it is often not practical for another processor that requires access to the shared resource associated with that lock to do anything except wait for the lock to be released, also referred to herein as the lock being cleared. For example, if a processor is handling an interrupt from a device it may need to add data received from the device to a shared queue. If another processor is removing data from the queue, the first processor must wait until the queue is in a consistent state and the lock has been released before it can then set the lock and add the new data to the queue. It cannot return from the interrupt handler until the data has been added to the queue, and hence it must wait.
In circumstances such as these, it is known to provide a “spin-lock” mechanism. In accordance with this mechanism, a processor requiring access to the protected data will attempt to obtain the lock, this involving reading the lock and then setting the lock if the read operation indicates that the lock is currently cleared. If the lock cannot be obtained, the processor repeatedly reads the lock value in a tight loop until the lock becomes available. At this point, the processor can then attempt once again to obtain the lock.
In a multi-processing system where low power consumption is desirable, this tight read loop is undesirable because energy is being consumed to no useful effect, and additionally in systems implementing multi-threading, the execution of spin-locks by waiting threads may be highly detrimental to performance.
Accordingly, it would be desirable to provide an improved technique for controlling access to a shared resource.